package com.ruoyi.shop.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.domain.ShopPickupStation;
import com.ruoyi.shop.service.IShopPickupStationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自提点Controller
 * 
 * @author Alan Zhang
 * @date 2021-10-14
 */
@Controller
@RequestMapping("/shop/station")
public class ShopPickupStationController extends BaseController
{
    private String prefix = "shop/station";

    @Autowired
    private IShopPickupStationService shopPickupStationService;

    @RequiresPermissions("shop:station:view")
    @GetMapping()
    public String station()
    {
        return prefix + "/station";
    }

    /**
     * 查询自提点列表
     */
    @RequiresPermissions("shop:station:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopPickupStation shopPickupStation)
    {
        startPage();
        List<ShopPickupStation> list = shopPickupStationService.selectShopPickupStationList(shopPickupStation);
        return getDataTable(list);
    }

    /**
     * 导出自提点列表
     */
    @RequiresPermissions("shop:station:export")
    @Log(title = "自提点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopPickupStation shopPickupStation)
    {
        List<ShopPickupStation> list = shopPickupStationService.selectShopPickupStationList(shopPickupStation);
        ExcelUtil<ShopPickupStation> util = new ExcelUtil<ShopPickupStation>(ShopPickupStation.class);
        return util.exportExcel(list, "自提点数据");
    }

    /**
     * 新增自提点
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存自提点
     */
    @RequiresPermissions("shop:station:add")
    @Log(title = "自提点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopPickupStation shopPickupStation)
    {
        return toAjax(shopPickupStationService.insertShopPickupStation(shopPickupStation));
    }

    /**
     * 修改自提点
     */
    @GetMapping("/edit/{stationId}")
    public String edit(@PathVariable("stationId") Long stationId, ModelMap mmap)
    {
        ShopPickupStation shopPickupStation = shopPickupStationService.selectShopPickupStationByStationId(stationId);
        mmap.put("shopPickupStation", shopPickupStation);
        return prefix + "/edit";
    }

    /**
     * 修改保存自提点
     */
    @RequiresPermissions("shop:station:edit")
    @Log(title = "自提点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopPickupStation shopPickupStation)
    {
        return toAjax(shopPickupStationService.updateShopPickupStation(shopPickupStation));
    }

    /**
     * 删除自提点
     */
    @RequiresPermissions("shop:station:remove")
    @Log(title = "自提点", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopPickupStationService.deleteShopPickupStationByStationIds(ids));
    }
}
